package com.example.onlineeducation.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.example.onlineeducation.base.BaseViewModel
import com.example.onlineeducation.data.model.ExamRecordListDataModel
import com.example.onlineeducation.data.model.OfflineExamListDataModel
import com.example.onlineeducation.repository.OfflineRepository
import kotlinx.coroutines.flow.collectLatest


class MainOfflineExamVM : BaseViewModel() {
    private val mStudyRepository: OfflineRepository by lazy { OfflineRepository(mApiService) }


    private val _mOfflineExamList = MutableLiveData<PagingData<OfflineExamListDataModel>>()
    val mOfflineExamList: LiveData<PagingData<OfflineExamListDataModel>> = _mOfflineExamList


    fun getOfflineExamList(proId: String) = ycLaunch {
        mStudyRepository.getOfflineExamList(proId).cachedIn(viewModelScope).collectLatest {
            _mOfflineExamList.postValue(it)
        }
    }
}
